#lang racket


(require svn)

(provide racket-version
         racket-dir
         
         rosetta-version
         rosetta-version-major
         rosetta-version-minor
         rosetta-version-string
         rosetta-dir
         
         rosetta-update
         
         rosetta-changelog-2.0
         rosetta-changelog-2.1
         rosetta-changelog-2.2
         
         format-changelog
         rosetta-changelog
         
         ; repository
         
         rosetta-repository-url
         rosetta-repository-trunk
         rosetta-repository-tags)


(define racket-version (make-parameter (version)))
(define racket-dir (make-parameter (format "~A\\~A\\collects\\" (find-system-path 'pref-dir) (racket-version))))

(define rosetta-version (make-parameter (cons 2 2)))
(define rosetta-version-major car)
(define rosetta-version-minor cdr)

(define (rosetta-version-string)
  (format "~A.~A" (rosetta-version-major (rosetta-version)) (rosetta-version-minor (rosetta-version))))

(define rosetta-dir (make-parameter (format "~Arosetta\\" (racket-dir))))


(define (rosetta-update)
  (svn-update (rosetta-dir)))


(define rosetta-changelog-2.0
  #<<LOG
Added 'append-first' which appends the first element of a list to the list itself.
Added 'bbox-inflate' which given a bounding box returns a new bounding box with inflated/deflated width, length and height.
Added 'call' which given a function and arguments calls that function (e.g., Common Lisp 'funcall').
Added 'map-append-tree' which performs the same as 'map-tree' but it uses 'append' as reducer function instead of 'cons'.
Added 'map-pair' which maps a list at the list level instead of the element level.
Added 'map-rest' which applies a function to the list tail preserving the list elements.
Added 'pyramid' primitive.
Added 'repeat' which given a list appends the list to itself 'n' times.
Added 'sign' which the returns the sign of a number using -1, 0 or 1.
Added 'surface' primitive that creates surfaces using 3 or 4 points/curves or a closed curve.
Added 'thicken' primitive.
Added Rhinoceros 3D implementations for 'on-right', 'on-front' and 'on-back'.
Added Rhinoceros 3D implementations for 'on-x', 'on-y'.
Added a 'range' macro to replace the previously defined confusing 'range' functions.
Added a convenience constructor for the 'spline' primitive.
Added a more general constructor to 'subtract' to receive a list as second argument.
Added a synthatic extension to the 'repeat' function in the range macro.
Added convenience point constructors 'xy', 'yz', 'xz', '+xy', '+yz' and '+xz'.
Added separate 'line' and 'line-closed' primitives to creates open and closed lines. Notice that 'line' can also create closed lines.
Added several highlevel constructors: 'arc-cs-p', 'bbox-shape', 'cone-frustrum-p', 'cylinder-p', 'pipe-center', 'pyramid-pp', 'move-*' and 'rotate-*'.
Changed 'last' semantics to return last element of a list instead of a list.
Changed function '*2' to work with multiple arguments.
Fixed 'sph-fi' performance.
Fixed Rhinoceros 3D implementation of 'on-z'.
Added 'last-pair' to return the list containing the last element of a list.
Renamed 'bounding-box' constructor to 'bbox'.
Renamed all parametric surfaces to 'skin'.
LOG
  )

(define rosetta-changelog-2.1
  #<<LOG
Added 'coord' constructors 'x', 'y' and 'z'.
Added 'arc', 'elliptical-arc', 'ellipse' and 'circle' more cases
Added 'rosetta-version', 'rosetta-version-major', 'rosetta-version-minor', 'rosetta-dir', 'rosetta-update', 'rosetta-changelog-2.0', 'format-changelog' and 'rosetta-changelog'
Added 'delete-shape' and 'get-shapes'
Added 'pi/3' constant
Added 'cone-p'
Added 'on' primitive
Added 'loft-closed'
Added 'uxy', 'uyz' and 'uxz'
Added 'scale-*' and 'mirror-*' primitives
Added 'every'
Added 'align' primitive
Added commutativity to 'mult-c' parameters.
Added high-level features to 'rectangle'
Added high-level features to constructors 'annulus', 'ngon' and 'star'
Added high-level features to 'box', 'cone', 'cone-frustrum', 'cylinder', 'pyramid', 'sphere' and 'rotate' primitives
Added 'rh:layer' primitive to Rhino backend
Added 'spline-closed', 'spline-tan' and 'spline-closed-tan'
Added 'render-with-floor!'
Added 'auto-view'
Changed coordinate systems as described in ISO 31-11.
Changed 'backend' not to load the backend multiple times in the same process; this causes geometric shapes not to be erased (this might be changed in the next commit)
Changed 'begin-draw' and 'end-draw' to include expression to be evaluated
Changed 'xy', 'yz' and 'xz' to take a point as parameter and act as a copy/replace constructor
Changed 'loft' to create open lofts always
Changed 'view' API
Extended 'align' primitive to support a list of symbols for type as well
Fixed 'spline-tan' closed splines
Removed 'on-x', 'on-y' and 'on-z'
Removed 'p?'
Removed 'circle-p'
Renamed 'sph-fi' to 'sph-phi'
Renamed 'donut' to 'annulus'
Renamed point selectors from 'x', 'y', and 'z' to 'xyz-x', 'xyz-y' and 'xyz-z' for consistency.
Renamed 'zero' to 'u0'
Renamed 'one' to 'uxyz'
Renamed 'zero?' to 'u0?' due to collision with Racket's 'zero?'
Renamed 'unit' to 'norm'; 'norm' normalizes a point
Renamed 'bbox-left' to 'bbox-x-neg', 'bbox-right' to 'bbox-x-pos', 'bbox-front' to ..., etc ...
Renamed 'parametrize' to 'par' to avoid confusion with 'parameterize'
Renamed struct 'point' to 'coord'
Renamed 'collinear-pxp' to 'collinear-cross-c' (previous name is accessible via #lang rosetta-racket)
Renamed 'p<\p' to 'angle-c' (previous name is accessible via #lang rosetta-racket)
Renamed 'p//p' to 'collinearity-c' (previous name is accessible via #lang rosetta-racket)
Renamed '+x' to 'add-x-c', '+y' to 'add-y-c', etc... (previous names are accessible via #lang rosetta-racket)
Renamed 'coord?' to 'is-coord' (previous name is accessible via #lang rosetta-racket)
Renamed 'u0?' to 'is-u0' (previous name is accessible via #lang rosetta-racket)
Removed 'render-with-floor-fn'
Removed 'list-rand'
Renamed 'view-2d-top' to 'view-ortho-top' and changed API
Renamed 'view-2d-top!' to 'view-ortho-top!'
Swapped parameter order in 'sweep'
LOG
  )

(define rosetta-changelog-2.2
  #<<LOG
  Added 'scale-center'
LOG
  )

(define (format-changelog version log)
  (displayln (format "Rosetta ~A.~A changes:" (rosetta-version-major version) (rosetta-version-minor version)))
  (displayln log))

(define (rosetta-changelog version)
  (match version
    ((cons 2 0) (format-changelog version rosetta-changelog-2.0))
    ((cons 2 1) (format-changelog version rosetta-changelog-2.1))
    ((cons 2 2) (format-changelog version rosetta-changelog-2.2))))


; repository

(define rosetta-repository-url (make-parameter "http://rosetta-lang.googlecode.com/svn/"))
(define rosetta-repository-trunk (make-parameter (format "~Atrunk/" (rosetta-repository-url))))
(define rosetta-repository-tags (make-parameter (format "~Atags/" (rosetta-repository-url))))